# Maintainer: Martell Malone <martellmalone@gmail.com>

_realname=wineditline
pkgbase=mingw-w64-${_realname}
pkgname=("${MINGW_PACKAGE_PREFIX}-${_realname}")
pkgver=2.101
pkgrel=4
pkgdesc="port of the NetBSD Editline library (mingw-w64)"
arch=('any')
license=('BSD')
url="http://mingweditline.sourceforge.net"
makedepends=("${MINGW_PACKAGE_PREFIX}-gcc" "${MINGW_PACKAGE_PREFIX}-cmake")
options=('staticlibs')
source=("https://sourceforge.net/projects/mingweditline/files/${_realname}-${pkgver}.tar.bz2"
        '001-fix-installing.patch'
        '002-fix-exports.patch'
        '003-dont-link-with-def.patch')
sha256sums=('854b536bfe231aba478136f5cf9f2baca0182894dae78e3fddbd83b75fe6dfc8'
            '92987daf0c67eecdfc62702c3adaa025e0363039cda58aa9ae0a66852341a737'
            '38e779fbdebf2f29038b598920e733a4a51638834013c3cc73fb85a7d50cffd2'
            '19077726758de7780cd68f3f47d8353516fd864ede1903d55280a1fb3dbe408d')

prepare() {
  cd ${_realname}-${pkgver}
  patch -p1 -i ${srcdir}/001-fix-installing.patch
  patch -p1 -i ${srcdir}/002-fix-exports.patch
  patch -p1 -i ${srcdir}/003-dont-link-with-def.patch

  rm -rf bin32 bin64 lib32 lib64
}

build() {
  mkdir -p build-${MINGW_CHOST}
  cd build-${MINGW_CHOST}

  MSYS2_ARG_CONV_EXCL="-DCMAKE_INSTALL_PREFIX=" \
  ${MINGW_PREFIX}/bin/cmake \
    -G"MSYS Makefiles" \
    -DCMAKE_INSTALL_PREFIX=${MINGW_PREFIX} \
    ../${_realname}-${pkgver}

  make
}

package() {
  cd ${srcdir}/build-${MINGW_CHOST}
  make DESTDIR=${pkgdir} install

  install -Dm644 ${srcdir}/${_realname}-${pkgver}/COPYING ${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/LICENSE
}
